#ifndef TINY_MUDUO_THREAD_H_
#define TINY_MUDUO_THREAD_H_

#include <pthread.h>

#include <functional>

#include "latch.h"

namespace tiny_muduo {

class Thread {
 public:
	typedef std::function<void ()> ThreadFunc;

	Thread(const ThreadFunc& func);
	~Thread(); 

	void StartThread(int thread_cnt);

 private:
	pthread_t pthread_id_;
	ThreadFunc func_;
	Latch latch_;
};       


struct ThreadData {

typedef tiny_muduo::Thread::ThreadFunc ThreadFunc;
 
ThreadFunc func_;
Latch* latch_;
int thread_cnt_;

ThreadData(ThreadFunc& func, Latch* latch, int thread_cnt)
		: func_(func),
			latch_(latch),
			thread_cnt_(thread_cnt) {
}

void RunOneFunc() {
	latch_->CountDown();
	latch_ = nullptr;  
	func_();
}
};

}
#endif
